package {
	import cmodule.lib3ds.CLibInit;
	
	import com.floorplanner.lib3ds.Lib3dsFile;
	
	import flash.display.Sprite;
	import flash.utils.ByteArray;
	
	public class Lib3ds extends Sprite {
		
		[Embed (source="../bin-debug/MIG-21.3ds", mimeType="application/octet-stream")]
		private var TestFile :Class;
		
		private var _lib3dsLibInit :CLibInit;
		private var _lib3ds :Object;
		/**
		 * 
		 */ 
		public function Lib3ds() {
			initLib3ds();
			test();
		}
		
		/**
		 * Initializes the Alchemy jpg encoder.
		 */
		private function initLib3ds():void {
			_lib3dsLibInit = new CLibInit();
			_lib3ds = _lib3dsLibInit.init();
		}
		
		/**
		 * 
		 */ 
		private function test( async:Boolean=true ):void {
			var filename :String = "MIG-21.3ds";
			var byteArray :ByteArray = new TestFile();
			 
			_lib3dsLibInit.supplyFile(filename, byteArray);
			
			var file :Lib3dsFile;
			
			if (async ) {
				file = _lib3ds.readFileAsync(onComplete, filename);
			} else {
				file = _lib3ds.readFile(filename);
				if(file) { 
					trace(file);
				}
			}
		}
		
		/**
		 * Fired when the 3ds file was completely parsed.
		 * 
		 * @param	result
		 */ 
		private function onComplete( result:Object ):void {
			trace("done");
		}
	}
}
